package com.example.thread;

import org.apache.commons.lang3.RandomUtils;

/**
 * @author YDF
 * @date 2019/12/31
 */
public class Test {
    public static void main(String[] args) {
        Master master = new Master(new Worker(), 10);
        for (int i = 0; i < 100; i++) {
            Task task = new Task();
            task.setId(i);
            task.setName("task:" + i);
            task.setPrice(RandomUtils.nextInt());
            master.submit(task);
        }
        long start = System.currentTimeMillis();
        master.execute();
        while (true) {
            if (master.isCompleted()) {
                long end = System.currentTimeMillis();
                int result = master.getResult();
                System.out.println("计算结束。耗时：" + (end - start) + "ms， 计算结果：" + result);
                break;
            }
        }
    }
}
